#include<stdio.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<unistd.h>
#include<arpa/inet.h>
#include<sys/select.h>
#include<mysql.h>
#include<string.h>

struct password
{
	char id[20];
	char passwd[20];
	int flag;
};

void group_chat(int connectfd,struct password pw)
{
	MYSQL mysql;
    	MYSQL_ROW row;
    	MYSQL_RES *res = NULL;
    	char mysql_insert[1000];
	int nflag=-1,fd;	
	if(NULL == mysql_init(&mysql)) 
	{  
	        printf("mysql_init(): %s\n", mysql_error(&mysql));  
        	return ;  
    	} 
    	if (NULL == mysql_real_connect(&mysql,  
			"localhost",  
                	"root",  
                	"root",  
                	"lts",  
                	 0,  
                	NULL,  
                	0)) 
	{  
        	printf("mysql_real_connect(): %s\n", mysql_error(&mysql));  
        	return;  
    	}  
	memset(mysql_insert,0,sizeof(mysql_insert));
	sprintf(mysql_insert,"select * from user where fd > 0");
   	if(mysql_query(&mysql,mysql_insert))
	{
		printf("mysql_query(): %s\n", mysql_error(&mysql));
		nflag=0;
	}
	else
    	{
        	res = mysql_store_result(&mysql);
        	while ((row = mysql_fetch_row(res))) 
		{
			fd=atoi(row[2]);
			if(fd>0&&fd!=connectfd)
			{
				send(fd,pw.passwd,sizeof(pw.passwd),0);
			}
			
		}
	}
			
		
		
	
}
